package com.wdc.贪心;
@SuppressWarnings("all")
public class E04Leetcode122 {
    public int maxProfit(int[] prices) {

        int profit = 0;
        int result = 0;
        for (int i = 1; i < prices.length; i++) {
            if ( prices[i - 1] < prices[i] ){
            profit = prices[i ] - prices[i - 1];
            }
            result += profit;
            profit = 0;


        }
        return result;
    }

    public static void main(String[] args) {
        int[] prices = {7,6,4,3,1};
        E04Leetcode122 e04Leetcode122 = new E04Leetcode122();
        System.out.println(e04Leetcode122.maxProfit(prices));
    }
}
